package et.item.drill;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.common.config.ConfigItems;
import thaumcraft.common.items.wands.ItemWandCasting;

/**
 * Created by winston_wang on 2017/7/7.
 */
public class ETItemChaosDrill extends ETItemDrill {
    public ETItemChaosDrill(){
        super(8.0f, 80.0f, 57000, 100, 1, 8,17.0f);
        setTextureName("et:itemVoidChaosDrill");
        setUnlocalizedName("chaosVoidDrill");
        MinecraftForge.EVENT_BUS.register(this);
    }
    @SubscribeEvent
    public void onBreak(BlockEvent.HarvestDropsEvent event){
        if (event.harvester != null
                && event.harvester.getCurrentEquippedItem() != null
                && event.harvester.getCurrentEquippedItem().getItem().equals(this)) {
            if (((EntityPlayer)event.harvester).inventory.hasItem(ConfigItems.itemWandCasting)){
                for(ItemStack itemStack : ((EntityPlayer)event.harvester).inventory.mainInventory){
                    if (itemStack!=null
                            &&itemStack.getItem().equals(ConfigItems.itemWandCasting)){
                        for (ItemStack i : event.drops) {
                            if (((ItemWandCasting)itemStack.getItem()).getVis(itemStack,Aspect.AIR)>=1000
                                    &&((ItemWandCasting)itemStack.getItem()).getVis(itemStack,Aspect.EARTH)>=1000
                                    &&((ItemWandCasting)itemStack.getItem()).getVis(itemStack,Aspect.FIRE)>=1000
                                    &&((ItemWandCasting)itemStack.getItem()).getVis(itemStack,Aspect.WATER)>=1000
                                    &&((ItemWandCasting)itemStack.getItem()).getVis(itemStack,Aspect.ORDER)>=1000
                                    &&((ItemWandCasting)itemStack.getItem()).getVis(itemStack,Aspect.ENTROPY)>=1000) {
                                ((ItemWandCasting)itemStack.getItem()).addRealVis(itemStack,Aspect.AIR,-1000,true);
                                ((ItemWandCasting)itemStack.getItem()).addRealVis(itemStack,Aspect.EARTH,-1000,true);
                                ((ItemWandCasting)itemStack.getItem()).addRealVis(itemStack,Aspect.FIRE,-1000,true);
                                ((ItemWandCasting)itemStack.getItem()).addRealVis(itemStack,Aspect.WATER,-1000,true);
                                ((ItemWandCasting)itemStack.getItem()).addRealVis(itemStack,Aspect.ORDER,-1000,true);
                                ((ItemWandCasting)itemStack.getItem()).addRealVis(itemStack,Aspect.ENTROPY,-1000,true);
                                EntityItem entityItem = new EntityItem(event.world, event.x, event.y, event.z, i);
                                event.world.spawnEntityInWorld(entityItem);
                            }
                        }
                    }
                }
            }
        }
    }
}
